<?php



class Database {
	private $mysqli = null;
	
	public function prepare($sql) {
		$stmt = $this->mysqli->prepare($sql);
		return $stmt;
	}
   
	public function connect(DBConfig $config) {
		$this->mysqli = new mysqli(
							$config->host,
							$config->user,
							$config->password,
							$config->db
						);
	   
		if ($this->mysqli->connect_error) {
			throw new Exception($this->mysqli->connect_error);
		}
	   
		$this->mysqli->set_charset("utf8");
	}
	
	public function ExecuteNonQuery($stmt) {
		if ($stmt->execute() == FALSE) {
			throw new Exception($this->mysqli->error);
		}
	}
   
	public function SelectOne($stmt) {
		if ($stmt->execute() == FALSE) {
			throw new Exception($this->mysqli->error);
		}

		$stmt->bind_result($ret);
	   
		$stmt->fetch();
	   
		$stmt->close();
	   	   
		return $ret;
	}
   
	public function close() {
		return $this->mysqli->close();
	}
}
